package com.wjjun.library.widget.dropdown;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.ViewDataBinding;

import com.wjjun.base.ui.viewmodel.BaseViewModel;
import com.wjjun.library.R;
import com.wjjun.library.viewmodel.CheckItemViewModel;

import org.jetbrains.annotations.NotNull;


/**
 * 网格布局+重置和完成按钮
 * author : wangjunjun
 * date   : 2021/10/21
 * desc   :
 */
public class GridMenuTabView extends BaseListMenuTabView {

    private int spanCount = 12;

    public GridMenuTabView(@NonNull Context context) {
        this(context, null);
    }

    public GridMenuTabView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public GridMenuTabView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.common_refresh_grid;
    }

    @Override
    protected void initList(ViewDataBinding viewDataBinding) {
        super.initList(viewDataBinding);
        itemListViewProxy.setSpanCount(spanCount);
    }

    public void setSpanCount(int count) {
        this.spanCount = count;
        if (itemListViewProxy != null) {
            itemListViewProxy.setSpanCount(spanCount);
        }
    }

    @Override
    public void onItemClick(@NotNull View view, @NotNull BaseViewModel itemViewModel) {
        if (!isShow()) {
            return;
        }
        if (itemViewModel instanceof CheckItemViewModel) {
            CheckItemViewModel checkItemViewModel = (CheckItemViewModel) itemViewModel;
            checkItemViewModel.onItemClick(itemListViewProxy.getAllData());
        }
    }
}
